package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.mapper.BusinessCommonMapper;
import com.ruoyi.system.service.IBusinessCommonService;
import com.ruoyi.system.tools.FastJsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 站点关联设备Service业务层处理
 * 
 * @author wzf
 * @date 2021-04-27
 */
@Service
public class BusinessCommonServiceImpl implements IBusinessCommonService
{
	@Autowired
	private BusinessCommonMapper businessCommonMapper;

	@Autowired
	private RedisCache redisCache;


	@Autowired
	private FastJsonUtil fjUtil;

	/**
	 * BUSINESSCOMMON端 : 获取泵站列表
	 * @param data
	 * @return String
	 */
	public JSONObject bsGetPumpStationList(String data) {
		// 构建ws接口返回值
		JSONObject resMain = new JSONObject();
		JSONObject resPart1 = new JSONObject();
		JSONArray resPart2 = new JSONArray();

		// 解析输入参数
		JSONObject obj = JSON.parseObject(data);

		// 验证访问密钥
		// 构建db参数
		Map<String, Object> paramMap = new HashMap<String, Object>();

		// 调用db接口
		List<Map<String, Object>> dataResults = businessCommonMapper.bsGetPumpStationList(paramMap);
		// 获取db接口返回值
		if(Constants.PROC_RETURN_OK == Integer.parseInt(paramMap.get("vErrVal").toString())){
			// 结果集处理
			resPart2 = fjUtil.getJSONArray(dataResults);
			// 存储过程正常处理
			resPart1.put(Constants.RESULT_JSON_PART1_RESULT, Constants.PROC_RETURN_OK);
		}else{
			// 存储过程异常处理
			resPart1.put(Constants.RESULT_JSON_PART1_RESULT, paramMap.get("vErrVal"));
			resPart1.put(Constants.RESULT_JSON_PART1_ERRMSG, paramMap.get("vErrMsg"));
		}

		// 合并返回值
		resMain.put(Constants.RESULT_JSON_PART1_NAME, resPart1);
		resMain.put(Constants.RESULT_JSON_PART2_NAME, resPart2);

		return resMain;
	}

}

	









